package leetcode.code1657;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public boolean closeStrings(String word1, String word2) {
		// 不一样长，false
		if (word1.length() != word2.length()) {
			return false;
		}
		int type1 = 0, type2 = 0;
		int[] cnt1 = new int[26], cnt2 = new int[26];
		char[] cs1 = word1.toCharArray(), cs2 = word2.toCharArray();
		for (int i = 0; i < word1.length(); i++) {
			int c1 = cs1[i] - 'a';
			int c2 = cs2[i] - 'a';
			type1 |= 1 << c1;
			type2 |= 1 << c2;
			cnt1[c1]++;
			cnt2[c2]++;
		}
		// 类型不一样，false
		if (type1 != type2) {
			return false;
		}
		Arrays.sort(cnt1);
		Arrays.sort(cnt2);
		// 没有类似数量，false
		for (int i = 0; i < 26; i++) {
			if (cnt1[i] != cnt2[i]) {
				return false;
			}
		}
		return true;
	}

	@Override
	public void debug4() {
		H.compare(true, this.closeStrings("abc", "bca"));
		H.compare(false, this.closeStrings("a", "aa"));
		H.compare(true, this.closeStrings("cabbba", "abbccc"));
		H.compare(true, this.closeStrings("abbcccdddd", "cbbdddaaaa"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
